var dropped = false;
function initPage() {
    jQuery("img#import_products_down").click(function() {
        if (jQuery("input#import_product_freetext").attr("datavalue") != "" && jQuery("input#import_product_freetext").attr("datavalue") != "by product name / HS code") {
            jQuery("input#import_product_freetext").hsInput("openfilteredlist", {
                filter : jQuery("input#import_product_freetext").val()
            });
        } else {
            jQuery("input#import_product_freetext").hsInput("openlist");
        }
/*
        openPopup("popup_productsearch", {
            width : 900,
            height : 400,
            title : "Search product",
            extraParams : {
                popup_id : "productsearch"
            }
        });
*/
    });
    jQuery("img#import_products_freetextsearch").click(function() {
        handleEnterKey(jQuery("input#import_product_freetext").val());
    });
    jQuery("img#import_products_freetextsearch").parents("div").first().dblclick(function() {
        handleEnterKey(jQuery("input#import_product_freetext").val());
    });
    jQuery("img#import_products_hs4search").click(function() {
        if (jQuery("input#code_import_product_freetext").val() != "") {
            redirect("list_importproducts", "", {
                hs2 : getHS2FromHS4(jQuery("input#code_import_product_freetext").val()),
                hs4 : jQuery("input#code_import_product_freetext").val()
            }, true);
        }
    });
    jQuery("img#import_products_hs4search").parents("div").first().dblclick(function() {
        if (jQuery("input#code_import_product_freetext").val() != "") {
            redirect("list_importproducts", "", {
                hs2 : getHS2FromHS4(jQuery("input#code_import_product_freetext").val()),
                hs4 : jQuery("input#code_import_product_freetext").val()
            }, true);
        }
    });
}

function startSearch(parameters, newWindow) {
    if (newWindow === undefined) { newWindow = true; }
    redirect("list_importproducts", "", parameters, newWindow);
}

function listyourcompany() {
    redirect("profile", "", {
        emptyProfile : 1
    }, true);
}

function handleEnterKey(inputString) {
    if (parseInt(inputString, 10) > 0) {
        redirect("list_importproducts", "", {
            hs2 : getHS2FromHS4(inputString),
            hs4 : inputString
        }, true);
    } else {
        redirect("list_importproducts", "", {
            freetext : inputString
        }, true);
    }
}
